package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.model.business.Product;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "业务模块-物资资料相关接口")
@RestController
@RequestMapping("/business/product")
public class ProductController {

    @Autowired
    private ProductService productService;


    @ApiOperation(value = "物资资料分页列表展示 && 条件查询")
    @GetMapping("/findProductList")
    public ResponseBean findProductList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            ProductVO productVO
    ){
        PageVO<Product> productList = productService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(productList);
    }

    @ApiOperation(value = "添加物资")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody Product product){
        productService.add(product);
        return ResponseBean.success();
    }

    @ApiOperation(value = "修改物资,数据回显")
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        Product product = productService.edit(id);
        return ResponseBean.success(product);
    }

    @ApiOperation(value = "修改物资")
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody ProductVO productVO,
                               @PathVariable Long id){
        productService.update(productVO);
        return ResponseBean.success();
    }

    @ApiOperation(value = "移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productService.remove(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "恢复物资")
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "删除物资")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        productService.delete(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "审核通过物资")
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }

    //入库记录中需要的方法
    @ApiOperation(value = "物资添加入库时回显所有product")
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam(value = "pageNum", defaultValue = "1")
                                                 Integer pageNum,
                                     @RequestParam(value = "pageSize",defaultValue = "5")
                                             Integer pageSize){
        PageVO<Product> productPageVO = productService.findProducts(pageNum,pageSize);
        return ResponseBean.success(productPageVO);
    }






}
